// pages/my/my.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

    college_name: '',
    major: '',
    major_category_code: '',
    year: ['2022', '2021', '2020'],
    undergraduate: [],

    listData: [
      { "code": "01", "text": "text1", "type": "type1" },
      { "code": "02", "text": "text2", "type": "type2" },
      { "code": "03", "text": "text3", "type": "type3" },
      { "code": "04", "text": "text4", "type": "type4" },
      { "code": "05", "text": "text5", "type": "type5" },
      { "code": "06", "text": "text6", "type": "type6" },
      { "code": "07", "text": "text7", "type": "type7" }
    ],
    
    array: ['', '男', '女'], 
    currIndex: 0,
    childName: '',
    sex: '',
    age: '',
    grade: '',
    date: '',
    showBlock: false,



    //专科院校
    junior_college: [],
    //  专业
    discipline: [],
    //年份
    selectYear: 2022,
  },

  changeYear: function (e) {
    this.setData({
      selectYear: this.data.year[e.detail.value]
    })
  },


  bindPickerChange: function (e) {
    this.setData({
      college_name: this.data.junior_college[e.detail.value].college_name,
      discipline: this.data.junior_college[e.detail.value].discipline
    })
  },
  bindPickerChangeB: function (e) {
    console.log(this.data.discipline[e.detail.value].discipline_name);
    console.log(this.data.discipline[e.detail.value].id);
    console.log(this.data.discipline[e.detail.value].major_category_code);
    this.setData({
      major: this.data.discipline[e.detail.value].discipline_name,
      major_category_code: this.data.discipline[e.detail.value].major_category_code
    })

  },


  // 查询本科院校
  query() {
    var that = this;
    const { selectYear, major_category_code } = this.data;
    wx.request({
      url: 'https://bangkeedu.com/api/undergraduate/getUndergraduatesByCondition',
      data: {
        year: selectYear,
        major_category_code
      },
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function (res) {
        if (res.statusCode == 200) {
          that.setData({
            // 将res.data保存在listDate方便我们去循环遍历
            undergraduate: res.data
          })
        }
        // console.log(that.data.undergraduate)
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })



    // console.log('a')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {//查询院校和专业
    var that = this;
    wx.request({
      url: 'https://bangkeedu.com/api/junior_college',
      method: 'GET', 
      header: {}, 
      success: function (res) {
        if (res.statusCode == 200) {
          console.log(res.data[0]);
          that.setData({
            junior_college: res.data[0],
          })
        }
      },
      fail: function () {
        // fail
        wx.showToast({
          icon: "none",
          mask: true,
          title: "接口调用失败，请稍后再试。",
        });

      },
      complete: function () {
        // complete

      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onToOpinion: function (e) {
    wx.navigateTo({
      url: '/pages/opinion/index',
    })
  },
  onToAbout: function (e) {
    wx.navigateTo({
      url: '/pages/about/index',
    })
  }
})